package main.java.DMDE.model;

import java.util.*;

import main.java.DMDE.model.relationships.Relationship;

/**
 * Class Entity
 */
abstract public class Entity {

	//
	// Fields
	//

	private String name = null;
	private UUID id = null;
	private List<Method> methods = null;
	private List<Relationship> relationships = null;
	//
	// Constructors
	//
	public Entity() {
	    methods = new ArrayList<Method>();
	    relationships = new ArrayList<Relationship>();
	}
	
	public Entity(String name, UUID id) {
		this.id = id;
		this.name = name;
		methods = new ArrayList<Method>();
		relationships = new ArrayList<Relationship>();
	}
	
	/**
	 * Set the value of name
	 * 
	 * @param newVar
	 *            the new value of name
	 */
	public void setName(String newVar) {
		name = newVar;
	}

	/**
	 * Get the value of name
	 * 
	 * @return the value of name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Get the value of id
	 * 
	 * @return the value of id
	 */
	public UUID getId() {
		return id;
	}

	public void addMethod(Method method) {
	    methods.add(method);
	}
	
	public void addRelationship(Relationship relationship) {
	    relationships.add(relationship);
	}
	
	public List<Method> getMethods() {
	    return methods;
	}

	public void setMethods(List<Method> methods) {
	    this.methods = methods;
	}

	public List<Relationship> getRelationships() {
	    return relationships;
	}

	public void setRelationships(List<Relationship> relationships) {
	    this.relationships = relationships;
	}

	public List<Method> getMethodsByName(String methodName) {
		if (this.methods == null)
			return null;
		List<Method> filteredMethods = new ArrayList<Method>();
		for(Method met : methods) {
			if (met.isNamed(methodName)) {
				filteredMethods.add(met);
			}
		}
		return filteredMethods;
	}
	
	public boolean equals(Object entity) {
		return entity instanceof Entity && this.name.equals(((Entity)entity).name);
	}
	
	public String toString(){
	    return this.name;
	}

	public void setId(UUID id2) {
		this.id = id2;
	}
}
